package com.ewanghuiju.app.ui.my.activity;

import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.model.bean.local.VipEquityBean;
import com.ewanghuiju.app.test.bean.PintuanHomeBannerBean;
import com.ewanghuiju.app.test.bean.TestBean;
import com.ewanghuiju.app.ui.my.adapter.VipCenterCantuanListAdapter;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.ArcViewTop;
import com.ewanghuiju.app.widget.popupwindow.VipTransformPopup;
import com.gyf.immersionbar.ImmersionBar;
import com.muddzdev.styleabletoast.StyleableToast;
import com.stx.xhb.androidx.XBanner;

import java.util.ArrayList;
import java.util.List;

import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 会员权益中心页面
 * @time 2020/2/19
 */
public class VipCenterActivity extends SimpleActivity {
    //    @BindView(R.id.iv_order_recond)
//    ImageView ivOrderRecond;
    @BindView(R.id.xbanner)
    XBanner xbanner;
    @BindView(R.id.arcView)
    ArcViewTop arcView;
    @BindView(R.id.layout_top)
    RelativeLayout layoutTop;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.cradview)
    CardView cradview;
    @BindView(R.id.tv_ljyq)
    TextView tvLjyq;
    @BindView(R.id.tv_title)
    TextView tvTitle;


    private VipCenterCantuanListAdapter vipCenterCantuanListAdapter;

    private VipTransformPopup vipTransformPopup;

    @Override
    protected int getLayout() {
        return R.layout.activity_vip_center;
    }

    @Override
    protected void initEventAndData() {
        mToolbar.setBackground(null);
        mToolbar.setNavigationIcon(null);
        tvTitle.setTextColor(ContextCompat.getColor(mContext, R.color.white));
        initBanner();
//        initRecyclerView();
    }


    /**
     * 加载banner
     */
    public void initBanner() {
        //测试数据  测试bean
        List<PintuanHomeBannerBean> bannerList = new ArrayList<>();
        PintuanHomeBannerBean bean = new PintuanHomeBannerBean(TestBean.mUrl);
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean(TestBean.mUrl);
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        bean = new PintuanHomeBannerBean(TestBean.mUrl);
        bean.setResId(R.mipmap.bg_splash);
        bannerList.add(bean);
        xbanner.setBannerData(R.layout.banner_vip_center, bannerList);
        //加载广告图片
        xbanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
//                ImageView riv = view.findViewById(R.id.banner_image);
//                Glide.with(mContext).load(R.mipmap.test_banner).skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE).into(riv);
            }
        });
        xbanner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {

                } else {

                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    private void initRecyclerView(List<VipEquityBean> vipEquityBeans) {
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        vipCenterCantuanListAdapter = new VipCenterCantuanListAdapter(R.layout.item_vip_center_cantuan_list);
        recyclerView.setAdapter(vipCenterCantuanListAdapter);
        vipCenterCantuanListAdapter.setNewData(vipEquityBeans);
    }

    @OnClick({R.id.tv_ljyq})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_ljyq:
                if (vipTransformPopup == null) {
                    vipTransformPopup = new VipTransformPopup(mContext);
                }
                vipTransformPopup.setPopupGravity(Gravity.BOTTOM);
                vipTransformPopup.showPopupWindow();
                break;
            default:
                break;
        }
    }

    @Override
    protected int getTitleIntText() {
        return R.string.vip_center_title;
    }

    @Override
    protected void setOptionsMenu() {
        super.setOptionsMenu();
        menuItemFirse.setIcon(R.mipmap.icon_vip_center_order_recond);
        menuItemFirse.setVisible(true);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_time:
                StyleableToast.makeText(mContext, "点击", Toast.LENGTH_SHORT, R.style.mytoast).show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .init();
    }
}
